package com.dqhl.community.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.dqhl.community.R;
import com.dqhl.community.adapter.HealthRecordAdapter;
import com.dqhl.community.base.BaseActivity;
import com.dqhl.community.model.HealthRecordBean;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.JsonUtils;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.List;

/**
 * Created by LIENLIN on 2016/9/11.
 * 社区医疗预约记录
 */
public class CommunityHealthRecordActivity extends BaseActivity implements View.OnClickListener {

    private ImageView ivTopBack;
    private TextView tvTopTitle;
    private ListView lvRecord;
    private TextView tvNoInfo;
    private List<HealthRecordBean> healthRecordBeen;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_community_health_record);
        initView();
        getData();
    }
    //  获取数据
    private void getData() {
//        showCustomLoadBar(R.string.loading);
        Log.d("CommunityHealth","userid="+app.getUserId());
        RequestParams params = new RequestParams(Config.Api.community_health);
        params.addBodyParameter("user_id",app.getUserId());
        x.http().post(params, new Callback.CommonCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Log.d("CommunityHealth","result="+result);
                int errCode = JsonUtils.getErrCode(result);
                String data = JsonUtils.getInfo(result, "data");
                Log.d("CommunityHealth","data="+data);
                if (errCode==0){
                    healthRecordBeen = JSON.parseArray(data, HealthRecordBean.class);
                    lvRecord.setAdapter(new HealthRecordAdapter(CommunityHealthRecordActivity.this,healthRecordBeen));

                }
            }
            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Log.d("CommunityHealth","ex="+ex.toString());
            }
            @Override
            public void onCancelled(CancelledException cex) {

            }
            @Override
            public void onFinished() {

            }
        });
    }

    private void initView() {
        ivTopBack = (ImageView) findViewById(R.id.iv_top_back);
        ivTopBack.setVisibility(View.VISIBLE);
        tvTopTitle = (TextView) findViewById(R.id.tv_top_title);
        tvTopTitle.setText(R.string.txt_healthy_record);
        lvRecord = (ListView) findViewById(R.id.lv_record);
        tvNoInfo = (TextView) findViewById(R.id.tv_no_info);

        ivTopBack.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_top_back:
                finish();
                break;
        }
    }

}
